<template>
<div>
  <title1></title1>
  <div class="mid">
    <div class="courseList">
      <!--    导航-->
      <div class="nav">
        <a-icon type="home" /> <span>首页</span>/<span>视频详情</span>
      </div>
      <!--    中间图片部分-->
      <div class="pic">
        <div class="pic-text">
          <img :src="list.coverFileUrl" alt="">
          <div class="text">
            <p>{{list.courseTitle}}</p>
            <p><span>累计</span>{{list.orderBy}}<span style="margin-right: 10px">人学习</span><a-rate v-model="value" disabled/></p>
            <div v-if="list.isFree==1?true:false">
              <p class="btn">免费</p>
              <button>立即观看</button>
            </div>
            <div v-else class="cost">
              <div>
                <p>￥{{list.payPrice}}<span>￥{{list.coursePrice }}</span></p>
                <p>{{list.discountDesc}}</p>
              </div>
              <button @click="isLogin">立即购买</button>
              <button @click="openNotification(list.courseId)">加入购物车</button>
            </div>
          </div>
        </div>
        <div class="collect" @click="likeIt">
          <a-icon type="heart" size="20px" v-show="isfree"/>
          <van-icon name="like" size="20px" color="red" v-show="!isfree" />
          <span>收藏</span>
        </div>
      </div>
      <!--    tab切换部分-->
      <div class="tab">
        <a-tabs default-active-key="1" @change="callback">
          <a-tab-pane key="1" tab="课程详情" v-html="list.courseDetail">
          </a-tab-pane>
          <a-tab-pane key="2" tab="目录" force-render>
            <div>
              <ul v-for="(item,index) in list.sections" :key="index">
                <nav ><a-icon type="cloud-download" /><span>收藏</span></nav>
                {{index+1}}、&nbsp;&nbsp;{{item.sectionName}}
               <li v-for="(value,i) in item.subSections" :key="i" @mouseenter="change(index,i)"  class="list">
                   <a-icon v-show="!(tab1==index&&tab2==i)" type="play-circle"  class="cal1"/>
                   <span v-show="list.isFree=='1'&&tab1==index&&tab2==i"  class="cal2" >观看</span>
                   <span v-show="list.isFree=='0'&&tab1==index&&tab2==i"  class="cal2" >试看</span>

                 {{index+1}}-{{i+1}}&nbsp;&nbsp;{{value.sectionName}}
               </li>
              </ul>
            </div>
          </a-tab-pane>
          <a-tab-pane key="3" tab="评论">
            <p>评论</p>
            <span style=" width: 440px;display: flex; justify-content: center ">
              <a-rate v-model="value" :tooltips="desc" />
              <span class="ant-rate-text" style="margin-top: 8px">{{ desc[value - 1] }}</span>
            </span>
            <textarea style="width: 100%;height: 300px;margin-top: 20px"></textarea>
            <button style="float: right;background: #00d086 ;color: white;outline: none;border: none">发表评论</button>
          </a-tab-pane>
        </a-tabs>
      </div>
    </div>
  </div>
</div>
</template>

<script>

import title1 from '../components/title1.vue'
import {getCourseDetail} from "@/api/api";
import {addShopping} from "@/api/api";

export default {
name: "CourseDetail",
  data() {
    return {
      list:{},
      value: 5,
      like:true,
      tab1:'',
      tab2:'',
      isfree:true,
      desc: ['terrible', 'bad', 'normal', 'good', 'wonderful'],
    };
  },
  methods: {
    callback(key) {
      console.log(key);
    },
    change(index,i){
      console.log(index,i);
      this.tab1=index
      this.tab2 = i

    },
    likeIt() {
      let that = this
      if (this.isfree) {
        this.isfree = !this.isfree
      } else {
        this.$confirm({
          title: '确定要取消收藏么？',
          okText:'依然爱你',
          cancelText:'舍弃你',
          onOk() {
            console.log('取消');
          },
          onCancel() {
            that.isfree = !that.isfree
          }
        })
      }
    },
    //   提示弹出框
    openNotification(e) {
      console.log()
      this.$store.dispatch("cart/addCartList",e)

      addShopping(this.$route.query.id).then(res=>{
        console.log(res);
        this.$store.dispatch("getShoppingCart")
      })

    },
    isLogin() {
      if(this.$store.state.isLogin){
        this.$store.commit("changeLoginVisible",false)

      }else{
        this.$store.commit("changeLoginVisible",true)
      }

    },


  },
  created(){
    getCourseDetail(this.$route.query.courseId).then(res=>{
      console.log(res)
      this.list = res.data
    })

  },
  components:{
    title1
  }
}
</script>

<style scoped lang="less">
.mid{
  width: 100%;
  background: #ddd;
}
.courseList {
  width: 1200px;
  margin: auto;
  height: auto;
  background: #fff;
  .nav{
    background: #ddd;
    padding: 10px 0;
    font-size: 16px;
    span{
      margin: 0 6px;
      color: #aaa;
    }
  }
  .pic{
    //padding-bottom: 30px;
    border-bottom: 10px solid #ddd;
    padding: 20px;
    display: flex;
    justify-content: space-between;
    .pic-text {
      display: flex;
      justify-content: space-around;
      img{
        width: 400px;
        height: 300px;
      }
      .text{
        margin: 20px;
        p:nth-child(1){
          font-size: 20px;
          color: black;
        }
        .btn {
         font-size: 30px;
          color: #00d086;
        }
        button {
          width: 160px;
          height: 45px;
          background: #00d086;
          color: white;
          line-height: 45px;
          font-size: 20px;
          outline: none;
        }
      }
    }
  }
  .collect {
    width: 100px;
    height: 30px;
    text-align: center;
    line-height: 30px;
    float: right;
    border: 1px solid black;

    span{
      margin-left: 10px;
    }
  }
  .tab {
    padding: 10px;
    div{
      ul{
        width: 100%;
        font-size: 20px;
        text-indent: 1em;
        nav{
          margin-right: 60px;
          width: 90px;
          height: 30px;
          font-size: 10px;
          background: cyan;
          //border: 1px solid #aaa;
          float: right;
          //text-align: center;
          line-height: 30px;
          //display: flex;
          //justify-content: space-around;
          i{
            color: white;
            float: left;
            margin-right: 2px;
            font-size: 20px;
            line-height: 30px;
          }
          span{

            text-align: left;
          }
        }
        //display: flex;
        //justify-content: space-around;
        li{
          width: 90%;
          height: 50px;
          font-size: 12px;
          color: #aaa;
          line-height: 50px;
          //border: 1px solid black;
          background: #eee;
          margin: 6px auto;
          text-indent: 2em;
          box-sizing: border-box;
        }
        li:hover{
          color: #00d086;
        }
      }


    }
  }
}
/deep/.cal1{
  float: right;
  font-size: 20px;
  margin:15px 20px
}
/deep/.cal2{
  float: right;
  font-size: 16px;
  margin:1px 20px;
}
.cost{
    div {
      height: 70px;
      margin-bottom: 10px;

      p:nth-of-type(1) {
        color: black;
        margin: 0 0 10px 0;

        span {
          color: red;
          text-decoration: line-through;
          font-size: 14px;
          margin: 0 10px;
        }
      }

      p:nth-of-type(2) {
        box-sizing: border-box;
        border: 1px solid #ffd591;
        border-radius: 2px;
        height: 22px;
        width: 64px;
        margin-right: 8px;
        padding: 0 7px;
        font-size: 12px;
        line-height: 20px;
        color: #fa8c16
      }
    }

    /deep/button:nth-of-type(1) {
      color: #fff;
      background: rgb(255, 128, 0)!important;
      margin-right: 20px;
      border: 2px solid rgb(255, 128, 0);
    }

    button:nth-of-type(2) {
      color: #fff;
      background-color: #00cf8c;
      border: 2px solid #00cf8c;
    }
  }

</style>